jsx3.require("jsx3.gui.Template");

jsx3.lang.Class.defineClass("ux.core.gui.FormPanel", jsx3.gui.Template.Block, null,
    function(PANEL, panel) {

        panel.init = function(strName) {
            this.jsxsuper(strName);
        }

        panel.onSetChild = function(objChild) {
            return objChild.instanceOf("ux.core.gui.TextFieldFormRow");
        }

        panel.onSetParent = function(objParent) {
            var ret = this.jsxsuper(objParent);
            if(objParent.instanceOf("ux.core.gui.Form")) {
            }
            else {
                ret = false;
            }
            return ret;
        }

        panel.setChild = function(objChild, intPersist, strSourceURL, strNS) {
            var children = this.getChildren();
            var prevChild = null;
            if(children.length > 0) {
                prevChild = children[children.length - 1];
            }
            var ret = this.jsxsuper(objChild, intPersist, strSourceURL, strNS);
            if(this.getParent()) {
                if(prevChild) {
                    this.getParent().addChildRow(objChild, prevChild);
                }
                else {
                    var me = this;
//                    setTimeout(function() {
                        me.getParent().rescanAndAddChildren(objChild);
//                    },0);
                }
            }
            return ret;
        }

        panel.adoptChild = function(objChild, bRepaint, bForce) {
            var children = this.getChildren();
            var prevChild = null;
            if(children.length > 0) {
                prevChild = children[children.length - 1];
            }
            var ret = this.jsxsuper(objChild, bRepaint, bForce);
            if(this.getParent()) {
                if(prevChild) {
                    this.getParent().addChildRow(objChild, prevChild);
                }
                else {
                    var me = this;
//                    setTimeout(function() {
                        me.getParent().rescanAndAddChildren(objChild);
//                    },0);
                }
            }
            return ret;
        }

        panel.setCDFAttribute = function(formrow, strAttName) {
            this.cdfattributes[formrow] = strAttName;
        }

        panel.getCDFAttribute = function(formrow) {
            return this.cdfattributes[formrow];
        }

        panel.getCDFAttributes = function() {
            return this.cdfattributes
        }

        panel.getNextFormRow = function(formrow) {
            return this.getParent().getNextFormRow(formrow);
        }

        panel.getPreviousFormRow = function(formrow) {
            return this.getParent().getPreviousFormRow(formrow);
        }

        PANEL.templateXML = ux.core.System.getServer().loadInclude("jsxaddin://user!LiveCore/classes/ux/core/gui/templates/formpanel.xml","formPanel","xml").toString();
//        jsx3.log(PANEL.templateXML);
        jsx3.gui.Template.compile(PANEL.templateXML,PANEL.jsxclass);
    }
);